/*
 * Copyright 2007 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.dev.jas.as.impl;

import com.google.gwt.dev.js.ast.JsProgram;
import com.google.gwt.dev.js.ast.JsScope;
import com.google.gwt.dev.jas.as.impl.JsObfuscateNamer;

import java.util.HashSet;

/**
 * More restrictive obfuscation namer for ActionScript 2.0 output.
 */
public class JsAS2ObfuscateNamer extends JsObfuscateNamer {

  private final HashSet<String> as2keywords = new HashSet<String>();

  public static void exec(JsProgram program) {
    new JsAS2ObfuscateNamer(program).execImpl();
  }

  public JsAS2ObfuscateNamer(JsProgram program) {
    super(program);
    as2keywords.add("lt");
    as2keywords.add("le");
    as2keywords.add("gt");
    as2keywords.add("ge");
    as2keywords.add("eq");
    as2keywords.add("ne");
    as2keywords.add("and");
    as2keywords.add("or");
    as2keywords.add("is");
    as2keywords.add("as");
  }

  @Override
  protected boolean isLegal(JsScope scope, String newIdent) {
    if (as2keywords.contains(newIdent))
        return false;
    return super.isLegal(scope, newIdent);
  }
}
